package com.wzf.greattruth.zookeeper.operator;

import org.apache.commons.lang3.StringUtils;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;

import com.wzf.greattruth.zookeeper.ZookeeperManager;
import com.wzf.greattruth.zookeeper.helper.ZookeeperHelper;

public class ZooKeeperNodeDataOperator extends ZooKeeperOperator<String, byte[]> {

    public ZooKeeperNodeDataOperator(ZooKeeper zookeeper, String dir) {
        super(zookeeper, dir);
    }

    @Override
    protected byte[] doOperate(String nodeId) throws KeeperException, InterruptedException {
        ZooKeeper zookeeper = getZookeeper();
        String dir = getDir();

        if (StringUtils.isBlank(nodeId)) {
            return null;
        }
        String nodePath = ZookeeperHelper.getNodePath(dir, nodeId);
        byte[] datas = zookeeper.getData(nodePath, false, null);

        return datas;
    }

}
